using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;
using AtletIS.DomainModel.Entities.Main;

namespace AtletIS.Database.Mapping.Main
{
    public class ContactMap : EntityTypeConfiguration<Contact>
    {
        public ContactMap()
        {
            // Primary Key
            this.HasKey(t => t.ID);

            // Properties
            this.Property(t => t.ClubId)
                .HasMaxLength(5);

            this.Property(t => t.Firstname)
                .HasMaxLength(50);

            this.Property(t => t.Surname)
                .HasMaxLength(50);

            this.Property(t => t.Position)
                .HasMaxLength(50);

            this.Property(t => t.City)
                .HasMaxLength(50);

            this.Property(t => t.Adress)
                .HasMaxLength(50);

            this.Property(t => t.Email)
                .HasMaxLength(50);

            this.Property(t => t.Phone)
                .HasMaxLength(50);

            this.Property(t => t.Other)
                .HasMaxLength(50);

            // Table & Column Mappings
            this.ToTable("Contacts");
            this.Property(t => t.ID).HasColumnName("ID");
            this.Property(t => t.ClubId).HasColumnName("ClubId");
            this.Property(t => t.Firstname).HasColumnName("Firstname");
            this.Property(t => t.Surname).HasColumnName("Surname");
            this.Property(t => t.Position).HasColumnName("Position");
            this.Property(t => t.City).HasColumnName("City");
            this.Property(t => t.Adress).HasColumnName("Adress");
            this.Property(t => t.Email).HasColumnName("Email");
            this.Property(t => t.Phone).HasColumnName("Phone");
            this.Property(t => t.Other).HasColumnName("Other");
            this.Property(t => t.WebId).HasColumnName("WebId");

            // Relationships
            this.HasOptional(t => t.Club)
                .WithMany(t => t.Contacts)
                .HasForeignKey(d => d.ClubId);

        }
    }
}
